package com.wanmait.community.controller;

import com.github.pagehelper.PageInfo;
import com.wanmait.community.entity.Car;
import com.wanmait.community.service.CarParkingSpotService;
import com.wanmait.community.service.CarService;
import com.wanmait.community.util.AjaxResult;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

@RestController
@RequestMapping("car")
@Transactional
public class CarController {
    @Resource
    private CarService carService;
    @Resource
    private CarParkingSpotService carParkingSpotService;
    //添加车辆信息
    @PostMapping("add")
    public AjaxResult add(@RequestBody Car car) {
        carService.addCar(car);
        carParkingSpotService.getinsert(car.getId());
        return AjaxResult.success();




    }
    //逻辑删除
    @DeleteMapping("{id}")
    public AjaxResult update( Integer id) {
        carService.updateCar(id);
        return AjaxResult.success();
    }
    //查询加分页
    @PostMapping("pageInfo")
    public AjaxResult pageInfo(@RequestBody Car car,Integer pageNum) {
        Integer pageSize=6;
        PageInfo<Car> pageInfo =  carService.getCarList(car,pageNum,pageSize);
        return AjaxResult.success().put("pageInfo", pageInfo);
    }

    //根据id查询
    @GetMapping("{id}")
    public AjaxResult get(@PathVariable Integer id) {
        Car car =  carService.getCarById(id);
        return AjaxResult.success().put("car", car);
    }
    //修改信息
    @PostMapping("handleupdate")
    public AjaxResult handleUpdate(@RequestBody Car car) {
        carService.handleupdate(car);
        return AjaxResult.success();
    }
}

